<?=$header?>

<script src="<?=base_url();?>system/jqueryFileTree/jquery.js" type="text/javascript"></script>
<script src="<?=base_url();?>system/jqueryFileTree/jqueryFileTree.js" type="text/javascript"></script>
<script src="<?=base_url();?>system/jqueryFileTree/jquery.easing.js" type="text/javascript"></script>

<p>
<div class="option_box" style="width:500px;">
	<h2>File Manager</h2>
	<div style="padding:5px;">
	<div id="file_browser"></div>
	</div>
</div>

<br />

<div class="option_box" style="width:500px;">
	<a onclick="toggle('#create_box');"><h2>Create a Folder</h2></a>
	<div id="create_box" style="display:none;">
	<div style="padding:8px;">
		<div id="dir_name"></div>
		<? 
		echo '<table>';
		echo '<tr><td>Folder Name</td><td><input type="text" id="folder_name" name="folder_name" value="" maxlength="50" size="20"  /></td></tr>';
		echo '<tr><td colspan="2"><input type="button" id="subbut" value="Add Folder" onclick="addFolder();" /></td></tr>';
		echo '</table>';
		?>
	</div>
	</div>
</div>

<script type="text/javascript">
function loadFiles(){
	$(document).ready( function() {
	    $('#file_browser').fileTree({
	      root: '/',
	      script: '<?=base_url();?>system/jqueryFileTree/jqueryFileTree.php',
	      multiFolder: false
	    }, function(file) {
			//window.open(file);
	    });
	});
}
loadFiles();

function addFolder(){
	$(document).ready( function() {
	    $.ajax({
		    url: "<?=base_url();?>ajax/addFolder",
		    type: 'POST',
			data: { dirname: $("#folder_name").val() },
		    timeout: 10000,
		    success: function(){
		        loadFiles();
		    }
		});
	});
}

function deleteFolder(dir){
	if(confirm('Are you sure you want to delete the folder "'+dir+'"?')){
		$(document).ready( function() {
		    $.ajax({
			    url: "<?=base_url();?>ajax/deleteFolder",
			    type: 'POST',
				data: { dirname: dir },
			    timeout: 10000,
			    success: function(){
			        loadFiles();
			    }
			});
		});
	}
}

function uploadFiles(dir){
	window.location = 'files/upload/'+dir;
}

function deleteFile(fileName){
	if(confirm('Are you sure you want to delete the file "'+fileName+'"?')){
		$.ajax({
		    url: "<?=base_url();?>ajax/deleteFile",
		    type: 'POST',
			data: {file: fileName},
		    timeout: 10000,
		    success: function(){
		        loadFiles();
		    }
		});
	} 
}

function toggle(el){
	$(document).ready(function(){
		if ($(el).is(":hidden")) {
			$(el).slideDown("slow");
		} else {
			$(el).hide();
		}
	});
}
</script>
</p>

<?=$footer?>

</body>
</html>